package com.sundablog.service.impl.systemsetup.basicsetup.blogroll;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundablog.mapper.BlogrollMapper;
import com.sundablog.pojo.Blogroll;
import com.sundablog.pojo.BlogrollExample;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.systemsetup.basicsetup.blogroll.BlogrollService;

/**
 * 友情链接接口实现类
 * @ClassName:  BlogrollServiceImpl   
 * @Description:TODO(这里用一句话描述这个类的作用)   
 * @author: 哒哒 
 * @date:   2017年12月21日 下午11:32:48   
 *     
 * @Copyright: 2017 www.sundablog.com Inc. All rights reserved.
 */
@Service
public class BlogrollServiceImpl implements BlogrollService {

	@Autowired
	private BlogrollMapper blogrollMapper;
	
	/**
	 * 分页查询全部
	 * Title: listPagingQuery   
	 * Description:    
	 * @param page
	 * @param limit
	 * @return   
	 * @see com.sundablog.service.systemsetup.basicsetup.blogroll.BlogrollService#listPagingQuery(int, int)
	 */
	@Override
	public LayUiResult findPagingQuery(int page, int limit) {
		PageHelper.startPage(page, limit);
		BlogrollExample blogrollExample = new BlogrollExample();
		List<Blogroll> list = blogrollMapper.selectByExample(blogrollExample);
		PageInfo<Blogroll> pageInfo = new PageInfo<>(list);
		
		LayUiResult layUiResult = new LayUiResult();
		layUiResult.setCode(0);
		layUiResult.setMsg("");
		
		
		
		layUiResult.setCount(pageInfo.getTotal());
		layUiResult.setData(list);
		return layUiResult;
	}
	
	/**
	 * 添加友情链接接
	 * @Title: addBlogroll   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param blogroll
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	@Override
	public int addBlogroll(Blogroll blogroll) {
		blogroll.setCreateTime(new Date());
		blogroll.setUpdataTime(new Date());
		int i = blogrollMapper.insert(blogroll);
		return i;
	}
	
	/**
	 * 根据id获取一条友情链接接
	 * @Title: getBlogrollById   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: Blogroll      
	 * @throws
	 */
	@Override
	public Blogroll getBlogrollById(int id) {
		Blogroll blogroll = blogrollMapper.selectByPrimaryKey(id);
		return blogroll;
	}
	
	/**
	 * 修改友情链接数据
	 * @Title: updateBlogroll   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param blogroll
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	@Override
	public int updateBlogroll(Blogroll blogroll) {
		blogroll.setUpdataTime(new Date());
		int i = blogrollMapper.updateByPrimaryKeySelective(blogroll);
		return i;
	}

	/**
	 * 根据ID删除一条友情链接
	 * @Title: delectBlogrollById   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	@Override
	public int delectBlogrollById(int id) {
		int i = blogrollMapper.deleteByPrimaryKey(id);
		return i;
	}

	
}
